package com.jake.springboot.threadpool.service.impl;

import com.jake.springboot.threadpool.service.EmailService;
import com.jake.springboot.threadpool.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private EmailService emailService;

    @Override
    public boolean checkUsername(String username) throws Exception {
        if (username == null) {
            throw new Exception("用户名不能为null");
        }
        boolean isExisted = username.equalsIgnoreCase("jake") ||
                username.equalsIgnoreCase("heather");
        if (!isExisted) {
            emailService.sendEmail(username);
        }
        return !isExisted;
    }
}
